<?php



class Admin_Profile_Controller extends Base_Controller {

	public $restful = true;

    public function __construct()
    {
        parent::__construct();
        //--Your Code --//
        $this->theme->set_theme("admin") ;
    }
    
    
    public function get_index(){
    	
    	if (Auth::guest()) return Redirect::to('admin/login');
    	
    	if (!Auth::check())
    	{
    		return Redirect::to('admin/login');
    	}else{
    	
		$data['profile'] = Users::Where('id','=',Auth::user()->id)->first();
		
		$this->theme->title("Admin Profile");
    	return $this->theme->render('admin::profile',$data);
    	}
    }
	
    public function post_index(){
    	
    	$rules = array(
    	
    			'name' => 'required',
    			'username' => 'required',
    			'email' => 'required|email',
    			'password' => 'required|min:3',
    			'confirmpassword' => 'required|same:password'
    	
    	);
    	
    	if(Input::get('password') == TRUE){
    	$validator = Validator::make(Input::get(), $rules);
    	
    	$thisOrderID = Input::get('userID');
    	
    	
    	if( $validator->fails() )
    	{
    		return Redirect::back()->with_input()->with_errors($validator)->with('message','Invalid Operation !');
    	}
    	else
    	{
    	
    		$users =DB::table('users')
    		->where('id', '=', $thisOrderID)
    		->update(array(
    				
    				'name' => Input::get('name'),
    				'username' => Input::get('username'),
    				'email'  => Input::get('email'),
    				'password' => Hash::make(Input::get('password')),
    		)
    		);
    	}
    	}
    	else{
    		
    		$thisOrderID = Input::get('userID');
    		
    		$users =DB::table('users')
    		->where('id', '=', $thisOrderID)
    		->update(array(
    		
    				'name' => Input::get('name'),
    				'username' => Input::get('username'),
    				'email'  => Input::get('email'),
    			
    		)
    		);
    	}
    	
    		return Redirect::back()->with('message','Data Successfully Updated !');
    	
    	
    	
    	 
    }
	
}